package com.wyh.utils.sqlUtils.activity;

import com.wyh.entity.Activity;

public class updateActivitySqlDynamic {
    public String updateDynamic(Activity activity) {
        StringBuilder builder = new StringBuilder();
        if (activity.getName() != null) {
            if (builder.length() > 0) {
                builder.append(",");
            }
            builder.append("name = #{name}");
        }
        if (activity.getType() != null) {
            if (builder.length() > 0) {
                builder.append(",");
            }
            builder.append("type = #{type}");
        }
        if (activity.getTime() != null) {
            if (builder.length() > 0) {
                builder.append(",");
            }
            builder.append("time = #{time}");
        }
        if (activity.getAddress() != null) {
            if (builder.length() > 0) {
                builder.append(",");
            }
            builder.append("address = #{address}");
        }
        if (activity.getRemark() != null) {
            if (builder.length() > 0) {
                builder.append(",");
            }
            builder.append("remark = #{remark}");
        }
        if (activity.getOrganizer_user_id_fk() != null) {
            if (builder.length() > 0) {
                builder.append(",");
            }
            builder.append("organizer_user_id_fk = #{organizer_user_id_fk}");
        }
        StringBuilder sql = new StringBuilder();
        sql.append("UPDATE activity SET ");
        sql.append(builder);
        sql.append(" WHERE id = #{id}");
        System.out.println(sql);
        return sql.toString();
    }
}
